import React from 'react';
import { Tooltip, Icon } from 'antd';
import classnames from 'classnames';
import styles from './index.less';

export default function AntIcon({ title, button, disabled, type, size = 18, onClick, ...rest }) {
    const icon = (
        <div
            className={classnames({ [styles.button]: button })}
            onClick={disabled ? () => {} : onClick}
            style={{ cursor: onClick ? 'pointer' : '' }}
        >
            <Icon
                type={type}
                style={{ fontSize: `${size}px`, lineHeight: `${size}px`, cursor: onClick ? 'pointer' : '' }}
                className={classnames({ [styles.disabled]: disabled, [styles.icon]: !button })}
                {...rest}
            />
        </div>
    );

    if (!title) {
        return icon;
    }

    return <Tooltip title={title}>{icon}</Tooltip>;
}
